package com.newenergy.wisehome.gateway.manager;

public class DnaDeviceManager {
//    public static final String TAG = "LFX";
//    public boolean isLogin;
//    public Family mFamily;
//    public DeviceCategory mDevice;
//    public final List<BLDNADevice> LOCAL_DEVICES_MAP = new ArrayList<>();
//    public final List<BLDNADevice> SDK_DEVICES_MAP = new ArrayList<>();
//    private BLDNADevice mDnaDevice;
//
//    //懒汉单例模式
//    public static DnaDeviceManager getInstance() {
//        return Holder.INSTANCE;
//    }
//
//
//    private static class Holder {
//        public static final DnaDeviceManager INSTANCE = new DnaDeviceManager();
//    }
//
//    public void addSdkDevice(BLDNADevice device) {
//        for (BLDNADevice sdkDevice : SDK_DEVICES_MAP) {
//            if (sdkDevice.getDid().equals(device.getDid())) {
//                return;
//            }
//        }
//        BLLet.Controller.addDevice(device);
//        SDK_DEVICES_MAP.add(device);
//    }
//
//    public void addLocalDevice(BLDNADevice device) {
//        for (BLDNADevice localDevice : LOCAL_DEVICES_MAP) {
//            if (localDevice.getDid().equals(device.getDid())) {
//                return;
//            }
//        }
//        mDnaDevice = device;
//        LOCAL_DEVICES_MAP.add(device);
//    }
//
//    public void addModuleDevice(DeviceCategory device) {
//        if (device == null || mDnaDevice == null) {
//            Log.e(TAG, "addModuleDevice:device == null || mDnaDevice == null ");
//            return;
//        }
//        mDevice = device;
//        new AddModuleDeviceTask().execute(device.getName());
//    }
//
//
////    public void copyDnaDevice(BLDNADevice bldnaDevice){
////
////        String jsonString = bldnaDevice.toJSONString();
////        new BLDNADevice();
////
////    }
//
//
//    //添加新的家庭模块设备
//    class AddModuleDeviceTask extends AsyncTask<String, Void, BLModuleControlResult> {
//        @Override
//        protected BLModuleControlResult doInBackground(String... params) {
//
//
//            return addModuleDeviceAction(mDnaDevice, mFamily, mDevice);
//        }
//
//        @Override
//        protected void onPostExecute(BLModuleControlResult result) {
//            super.onPostExecute(result);
//            if (result.succeed()) {
//                toast("添加设备成功。请稍等。。。");
//                Log.i(TAG, "onPostExecute: 添加设备成功。请稍等。。。");
//            } else {
//                toast("添加设备失败：error = " + result.getError() + "   msg =" + result.getMsg());
//            }
//        }
//    }
//
//
//    public BLModuleControlResult addModuleDeviceAction(BLDNADevice bldnaDevice, Family family, DeviceCategory deviceCategory) {
//
//        BLFamilyInfo blFamilyInfo = BLLocalFamilyManager.getInstance().getCurrentFamilyAllInfo().getFamilyInfo();
//        String familyId = blFamilyInfo.getFamilyId();
//        String roomId = "";
//        String name = deviceCategory.getName();
//
//        Log.i(TAG, "bldnaDevice =  " + bldnaDevice.toJSONString());
//        //创建家庭模块
//        BLFamilyModuleInfo blFamilyModuleInfo = new BLFamilyModuleInfo();
//        blFamilyModuleInfo.setBLFamilyId(familyId);
//        blFamilyModuleInfo.setRoomId(roomId);
//
//        blFamilyModuleInfo.setName(name);
//        blFamilyModuleInfo.setModuleType(1);    // 模块类型 SP
////          blFamilyModuleInfo.setModuleType(3);
//        blFamilyModuleInfo.setFlag(0);
//        blFamilyModuleInfo.setOrder(1);
//        blFamilyModuleInfo.setFollowDev(1);     // 模块下挂载设备数 1
//
//
//        String groupId = mDevice.getGroupId();
//        //蓝牙设备
//        BLFamilyDeviceInfo deviceInfo = buildFamilyDeviceInfo(familyId, roomId, bldnaDevice);
//
//        deviceInfo.setName(name);
//        String mac = bldnaDevice.getMac().replace(":", "");
//        String did = mac + "0000" + "9b500000" + "0001" + "00" + groupId;
//        String pid = "0000000000000000000000009b500000";
//        deviceInfo.setDid(did);
//        deviceInfo.setPid(pid);
//
//        //模块挂载设备
//        BLFamilyModuleInfo.ModuleDeviceInfo moduleDeviceInfo = new BLFamilyModuleInfo.ModuleDeviceInfo();
//        moduleDeviceInfo.setDid(deviceInfo.getDid());
//        moduleDeviceInfo.setSdid(null);
//        moduleDeviceInfo.setOrder(1);
//        moduleDeviceInfo.setContent(null);
//
//        List<BLFamilyModuleInfo.ModuleDeviceInfo> moduleDevices = new ArrayList<>();
//        moduleDevices.add(moduleDeviceInfo);
//        blFamilyModuleInfo.setModuleDevs(moduleDevices);
//
//// Log.i(TAG, "mModuleInfo: " + blFamilyModuleInfo.toDictionary().toString());
//
//        BLModuleControlResult result = BLFamily.addModuleToFamily(blFamilyModuleInfo, blFamilyInfo, deviceInfo, null);
//        Log.i(TAG, "addModuleToFamily result=: msg = " + result.getMsg() +
//                "   ModuleId=" + result.getModuleId() +
//                "   error=" + result.getError() +
//                "   Version = " + result.getVersion());
//        return result;
//    }
//
//    private void toast(String s) {
//        Log.i(TAG, "toast: msg = " + s);
//    }
//
//
//    public BLFamilyDeviceInfo buildFamilyDeviceInfo(String familyId, String roomId, BLDNADevice bldnaDevice) {
//        BLFamilyDeviceInfo deviceInfo = new BLFamilyDeviceInfo();
//        deviceInfo.setBLFamilyId(familyId);
//        deviceInfo.setRoomId(roomId);
//        deviceInfo.setDid(bldnaDevice.getDid());
//        deviceInfo.setPid(bldnaDevice.getPid());
//        deviceInfo.setMac(bldnaDevice.getMac());
//        deviceInfo.setName(bldnaDevice.getName());
//        deviceInfo.setPassword((int) bldnaDevice.getPassword());
//        deviceInfo.setType(bldnaDevice.getType());
//        deviceInfo.setLock(false);
//        deviceInfo.setAeskey(bldnaDevice.getKey());
//        deviceInfo.setTerminalId(bldnaDevice.getId());
//        deviceInfo.setSubdeviceNum(1);
//        deviceInfo.setWifimac(bldnaDevice.getMac());
//        deviceInfo.setLongitude("");
//        deviceInfo.setLatitude("");
//        deviceInfo.setExtend("");
//        return deviceInfo;
//    }
}
